package cn.edu.hust.cm.lib;

/**
 * 简单java log工具
 * 
 * @author chenming
 *
 */
public final class JavaLog {
	private static final boolean LOG_ENABLE = true;
	private static final boolean DETAIL_ENABLE = true;

	private JavaLog() {
	}

	private static String buildMsg(String msg) {
		return buildMsg(msg, 4);
	}
	
	private static String buildMsg(String msg, int stackTraceIndex) {
		StringBuilder buffer = new StringBuilder();

		if (DETAIL_ENABLE) {
			final StackTraceElement stackTraceElement = Thread.currentThread()
					.getStackTrace()[stackTraceIndex];

			buffer.append("[ ");
			buffer.append(Thread.currentThread().getName());
			buffer.append(": ");
			buffer.append(stackTraceElement.getFileName());
			buffer.append(": ");
			buffer.append(stackTraceElement.getLineNumber());
			buffer.append(": ");
			buffer.append(stackTraceElement.getMethodName());
		}

		buffer.append("() ] _____ ");

		buffer.append(msg);

		return buffer.toString();
	}

	public static void v(String msg) {
		if (LOG_ENABLE && true) {
			System.out.println(buildMsg(msg));
		}
	}

	public static void d(String msg) {
		if (LOG_ENABLE && true) {
			System.out.println(buildMsg(msg));
		}
	}

	public static void i(String msg) {
		if (LOG_ENABLE && true) {
			System.out.println(buildMsg(msg));
		}
	}

	public static void w(String msg) {
		if (LOG_ENABLE && true) {
			System.out.println(buildMsg(msg));
		}
	}

	public static void w(String msg, Exception e) {
		if (LOG_ENABLE && true) {
			System.out.println(buildMsg(msg));
		}
	}

	public static void e(String msg) {
		if (LOG_ENABLE && true) {
			System.out.println(buildMsg(msg));
		}
	}

	public static void e(String msg, Exception e) {
		if (LOG_ENABLE && true) {
			System.out.println(buildMsg(msg));
		}
	}
}